<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#errMess {
				color: red;
				display: none;
			}
		</style>
	</head>
	<body>
		<form action="/newuser" method="get">
			<table>
				<tbody>
					<tr>
						<td>用户名</td>
						<td>
							<label for="username">
								<input type="text" name="username" id="username" placeholder="请输入用户名" required="required">
							</label>
						</td>
					</tr>
					<tr>
						<td>输入密码</td>
						<td>
							<label for="password1">
								<input type="password" name="password1" id="password1" placeholder="请输入密码" required="required">
							</label>
						</td>
					</tr>
					<tr>
						<td>再次输入密码</td>
						<td>
							<input type="password" id="password2" placeholder="请输入密码" required="required">
							<span id="errMess">两次输入的密码不同</span>
						</td>
					</tr>
					<tr>
						<td><button type="submit" id="checkButton">注册</button></td>
						<td><button type="button" onclick="location.href='/login'">我要登录</button></td>
					</tr>
				</tbody>
			</table>
		</form>
	</body>
	<script type="text/javascript">
		let checkButtonObj = document.getElementById('checkButton');
		let btnObj = document.getElementById('btn');
		let errMessObj = document.getElementById('errMess');

		checkButtonObj.onclick = function(e) {
			let password1 = document.getElementById('password1').value;
			let password2 = document.getElementById('password2').value;
			if (password1 !== password2) {
				e.preventDefault();
				errMessObj.style.display = 'inline-block';
			} else {
				errMessObj.style.display = 'none';
			}
		}
	</script>
</html>
